<?php
/**
 *
 * @category   babel 
 * @package    BABEL
 * @author     Hannes Magnusson <hannes.magnusson@gmail.com>
 * @copyright  2008 Team babel
 * @license    LGPL
 */

include 'includes/babel/babel_constants.php';
include 'classes/babel/Translation_Tasks.php';
include 'classes/babel/TranslationsPoints_Checks.php';

$obj_tpl->setFile("babel_translate", "babel/translate.html");
$obj_tpl->setBlock("babel_translate", "task_reason", "task_ref");

if (isset($_SESSION["user"]["profile"]["active_language"])) {
	$curr_lang_id = $_SESSION["user"]["profile"]["active_language"];
} else {
	trigger_error("You need to set your current active language in the profile", E_USER_ERROR);
}

$task = Babel_Translation_Task::getLeastProgressTask($curr_lang_id, false, $_SESSION["task"]["skip"]);

if (!($task instanceof Babel_Translation_Task)) {
	trigger_error("No tasks available at this time", E_USER_ERROR);
}

$tmp = PDODB::execQueryFetch("SELECT name FROM babel_languages WHERE language_id=?", PDO::FETCH_COLUMN, array($curr_lang_id));
if (!$tmp) {
	trigger_error("No languages available at this time", E_USER_ERROR);
}


$log = $task->getChangelog();
$suggestion = false;
if (!empty($log)) {
	$suggestion = array_shift($log);
}

$obj_tpl->setVar(array(
	'VAR_LANG_NAME'             => $tmp[0],
	'VAR_TRANSLATION_TEXT'      => nl2br($task->getOrginalString()),
	'VAR_CONTEXT'               => ($str = $task->getContext()) ? $str : '(Not available)',
	'VAR_SUGGESTION'            => $suggestion ? $suggestion : "Input translated text here",
));
$obj_tpl->setBlock("babel_translate", "changelog", "changelog_ref");
foreach($log as $str) {
	$obj_tpl->setVar("VAR_CHANGED_VALUE", htmlentities($str, ENT_QUOTES, "UTF-8"));
	$obj_tpl->parse("changelog_ref", "changelog", true);
}


$obj_tpl->pparse("babel_translate","babel_translate");
$_SESSION["task"]["last_task"] = serialize($task);
$_SESSION["task"]["last_id"] =  $task->getTranslationID();

